﻿using Shop.Model.Stock;
using Shop.Repository;

namespace Shop.Collect.lmpl
{
    internal class GoodsStockCollect : IGoodsStockCollect
    {
        private readonly IGoodsStockRepository _Repository;

        public GoodsStockCollect (IGoodsStockRepository repository)
        {
            this._Repository = repository;
        }
        public bool AddStock (StockAdd add)
        {
            long verId = this._Repository.Get(add.SkuId, a => a.Version);
            return this._Repository.AddStock(add, verId);
        }
        public void InitStock (long goodsId, long userId, Dictionary<long, int> stock)
        {
            this._Repository.InitStock(goodsId, userId, stock);
        }
        public int GetStock (long skuId)
        {
            return this._Repository.Get(skuId, a => a.CurStock);
        }
        public void LockStock (Dictionary<long, int> set)
        {
            this._Repository.LockStock(set);
        }
        public Result[] GetStocks<Result> (long[] goodsId) where Result : class, new()
        {
            return this._Repository.GetStocks<Result>(goodsId);
        }
        public Dictionary<long, int> GetStocks (long goodsId)
        {
            return this._Repository.GetStocks(goodsId);
        }
    }
}
